﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Do a Gaussian Edge Filter by blurring and then subtract...
    /// </summary>
    public class GaussianUnsharpSub : MacroFilter
    {
        protected GaussianBlur m_GaussianBlur = new GaussianBlur(20);
        protected Sub m_Sub = new Sub();
        
        /// <summary>
        /// Macro Filter constructor
        /// </summary>
        public GaussianUnsharpSub()
        {
            this.FilterList.Add(m_GaussianBlur);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            GaussianBlur gaussianBlur = new GaussianBlur(10);
            UnsafeBitmap bitmapBlurred = gaussianBlur.ExecuteCloned(_bitmap);
            int nIterations = 3;
            for (int i = 0; i < nIterations; i++)
            {
                gaussianBlur.Execute(bitmapBlurred);
            }
            UnsafeBitmap bitmapSource = _bitmap;
            UnsafeBitmap imageSource = bitmapBlurred;
            UnsafeBitmap bitmap = new Sub().Process(bitmapSource, imageSource);
            imageSource.Dispose();
            bitmapSource.Dispose();
            return bitmap;
        }
    }
}
